//package com.cssy.yd.logic.web;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import javax.annotation.Resource;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import net.sf.json.JSONObject;
//
//import org.apache.commons.lang.StringUtils;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.validation.BindingResult;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//
//import com.cssy.base.web.BaseController;
//import com.cssy.base.web.BodyMsg;
//import com.cssy.yd.basic.entity.BasicMaterialsDO;
//import com.cssy.yd.basic.entity.BasicStorageinfoDO;
//import com.cssy.yd.basic.service.IBasicMaterialsService;
//import com.cssy.yd.basic.service.IBasicStorageService;
//import com.cssy.yd.dock.entity.Xxm2eJobCompleteDO;
//import com.cssy.yd.dock.service.IXxm2eJobCompleteService;
//import com.cssy.yd.logic.entity.LogicMaterialReturnItemDO;
//import com.cssy.yd.logic.entity.LogicMesWareDO;
//import com.cssy.yd.logic.entity.LogicMesWareItemDO;
//import com.cssy.yd.logic.service.ILogicMesWareItemService;
//import com.cssy.yd.logic.service.ILogicMesWareService;
//import com.plat.helper.JqGridHandler;
//import com.plat.helper.SearchCondition;
//import com.plat.helper.SearchConditions;
//import com.plat.helper.SearchResult;
//import com.plat.util.DateUtil;
//import com.plat.util.GlobalResLoader;
//import com.plat.util.OperationFlag;
//import com.plat.util.SessionUtil;
//import com.plat.util.json.AjaxUtil;
//import com.plat.util.json.OutJsonGrid;
//
//@Controller
//@RequestMapping("yd/logic/logicMesWare")
//public class LogicMesWareController extends BaseController<LogicMesWareDO>{
//	private static final String MANAGER = "/yd/logic/mesware/MesWareManager";// 列表页面
//	private static final String EIDT = "/yd/logic/mesware/MesWareOperation";// 添加、修改、显示页面
//	
//	@Resource(name="logicMesWareService")
//	private ILogicMesWareService logicMesWareService;
//	
//	@Resource(name="xxm2eJobCompleteService")
//	private IXxm2eJobCompleteService xxm2eJobCompleteService;
//	
//	@Resource(name="basicMaterialsService")
//	private IBasicMaterialsService basicMaterialsService;
//	
//	@Resource(name="basicwhService")
//	private IBasicStorageService basicwhService;
//	
//	@Resource(name="logicMesWareItemService")
//	private ILogicMesWareItemService logicMesWareItemService;
//	
//	@Override
//	public String manager(HttpServletRequest request, Model model)
//			throws Exception {
//		return MANAGER;
//	}
//
//	@Override
//	public void list(HttpServletRequest request, HttpServletResponse response)
//			throws Exception {
//		JqGridHandler hander=new JqGridHandler(request);
//		 SearchConditions scs = new SearchConditions();
//		 hander.getWheres(scs);
//		 scs.setOrderBy("dctime desc");
//		 SearchResult result= logicMesWareService.findListByExample(scs);
//		 OutJsonGrid out=new OutJsonGrid(result);
//		 out.printJSon(response);
//		
//	}
//
//	@Override
//	public String operationForm(HttpServletRequest request,  @PathVariable String id,
//			 @PathVariable String flag, Model model) throws Exception {
//		if (OperationFlag.ADD.equals(flag)) {
//			List<String> xList =   xxm2eJobCompleteService.findBylotIdAll();
//			model.addAttribute("flag","ADD");
//			model.addAttribute("xList", xList);
//		} else {
//			LogicMesWareDO logicMesWareDO  = logicMesWareService.findListById(id);
//			/*SearchConditions scs = new SearchConditions();
//			scs.setOrderBy("code");
//			scs.addCondition("meswareid", logicMesWareDO.getId(),SearchCondition.OP_EQUAL);
//			List<LogicMesWareItemDO> itemDOs =  logicMesWareItemService.findListByExample(scs).getResults();*/
//			model.addAttribute("logicMesWareDO", logicMesWareDO);
//			//model.addAttribute("itemDOs", itemDOs);
//		}
//		return EIDT;
//	}
//	
//	@RequestMapping("/griditems")
//	public void griditems(HttpServletRequest request,HttpServletResponse response) throws Exception{
//		String id = request.getParameter("id");
//		if(StringUtils.isNotBlank(id)){
//			LogicMesWareDO logicMesWareDO  = logicMesWareService.findListById(id);
//			SearchConditions scs = new SearchConditions();
//			scs.setOrderBy("code");
//			scs.addCondition("meswareid", logicMesWareDO.getId(),SearchCondition.OP_EQUAL);
//			List<LogicMesWareItemDO> itemDOs =  logicMesWareItemService.findListByExample(scs).getResults();
//			OutJsonGrid out = new OutJsonGrid(itemDOs);
//			out.printJSon(response);
//		}
//	}
//
//	@Override
//	public Map<String, Object> save(HttpServletRequest request,
//			LogicMesWareDO curAP, BindingResult result, Model model)
//			throws Exception {
//		BodyMsg bodyMap=BodyMsg.getInstance();
//		String itemdata =request.getParameter("itemdata");
//		if(itemdata==null&&"".equals(itemdata)){
//			bodyMap.isFail();
//			bodyMap.configWebInfor("物料单内容不能为空！");
//			return bodyMap.modelMap;
//		}
//		try {
//			logicMesWareService.mesWareSave(request, curAP);
//			bodyMap.isSuccess();
//			bodyMap.configWebInfor(GlobalResLoader.getOpsuccess());
//			bodyMap.configWebId(curAP.getId());
//			
//		} catch (Exception e) {			
//			e.printStackTrace();
//			bodyMap.isFail();
//			bodyMap.configWebInfor(GlobalResLoader.getOpfailed()+e.getMessage());
//		}
//		return bodyMap.modelMap;
//	}
//
//	@Override
//	public Map<String, Object> delete(HttpServletRequest request,
//			HttpServletResponse response, Model model) throws Exception {
//		BodyMsg bodyMap = BodyMsg.getInstance();
//		try {
//			String ids = request.getParameter("ids");
//			String[] fields=ids.split(",");
//			for(String field : fields){
//				LogicMesWareDO lm=logicMesWareService.findListById(field);
//				if(lm!=null){
//					lm.setRemoved(1);
//					logicMesWareService.update(lm, SessionUtil.getUser(request));
//				}
//				Xxm2eJobCompleteDO xCompleteDO = new Xxm2eJobCompleteDO();
//				xCompleteDO.setShipNo(lm.getMeswarecode());
//				xCompleteDO.setProcessCode("1");
//				xxm2eJobCompleteService.update(xCompleteDO, SessionUtil.getUser(request));
//			}
//			bodyMap.isSuccess(GlobalResLoader.getOpsuccess());
//		} catch (Exception e) {
//			e.printStackTrace();
//			bodyMap.isFail(GlobalResLoader.getOpfailed() + e.getMessage());
//		}
//		return bodyMap.modelMap;
//	}
//	
//	
//	@RequestMapping(value = "/mesItemlist")
//	public void poitemlist(HttpServletRequest request,
//			HttpServletResponse response) throws Exception {
//		List<LogicMesWareItemDO> logicMesWareItemDOs = new ArrayList<LogicMesWareItemDO>();
//		String ID = request.getParameter("ID");
//		List<Xxm2eJobCompleteDO> list =	xxm2eJobCompleteService.findListByExample(ID);
//		LogicMesWareItemDO lItemDO = null;
//		for (int i = 0; i < list.size(); i++) {
//			lItemDO = new LogicMesWareItemDO();
//			SearchConditions scs = new SearchConditions();
//			scs.addCondition("code", list.get(i).getAssemblyItem());
//			List<BasicMaterialsDO> materialsDOs = basicMaterialsService.findListByExample(scs).getResults();
//			if(materialsDOs.size() >0){
//				lItemDO.setCode(materialsDOs.get(0).getCode());
//				lItemDO.setMaterialsid(materialsDOs.get(0).getId());
//				lItemDO.setName(materialsDOs.get(0).getName());
//				lItemDO.setSpec(materialsDOs.get(0).getSpec());
//				lItemDO.setUnit(materialsDOs.get(0).getUnit());
//				lItemDO.setPackageType(materialsDOs.get(0).getPackageType());
//			}
//			lItemDO.setReceivable(Double.parseDouble(list.get(i).getTransactionQty().toString()));
//			lItemDO.setReceived(Double.parseDouble(list.get(i).getTransactionQty().toString()));
//			lItemDO.setContainerNumber(list.get(i).getInternalBoxId());
//			lItemDO.setBatch(list.get(i).getMainLotId());
//			
//			if("PASS".equals(list.get(i).getBinDefine())){
//				lItemDO.setState("1");
//			}else if("NG".equals(list.get(i).getBinDefine())){
//				lItemDO.setState("2");
//			}else if("FAIL".equals(list.get(i).getBinDefine())){
//				lItemDO.setState("3");
//			}
//			logicMesWareItemDOs.add(lItemDO);
//		}
//		SearchConditions scs2 = new SearchConditions();
//		scs2.addCondition("code", list.get(0).getSubinventory());
//		List<BasicStorageinfoDO> basicStorageinfoDOs = basicwhService.findListByExample(scs2).getResults();
//		if(basicStorageinfoDOs.size() > 0){
//			request.setAttribute("whcode", basicStorageinfoDOs.get(0).getCode());
//			request.setAttribute("whname", basicStorageinfoDOs.get(0).getName());
//		}
//		request.setAttribute("transactionDate", list.get(0).getTransactionDate());
//		SearchResult result =new SearchResult();
//		result.setResults(logicMesWareItemDOs);
//		result.setRecordCount(logicMesWareItemDOs.size());
//		OutJsonGrid out = new OutJsonGrid(result);
//		
//		out.printJSon(response);
//
//	}
//	
//	
//	
//	
//	@RequestMapping(value = "/getWh")
//	public void getWh(HttpServletRequest request,HttpServletResponse response)throws Exception{
//		Map<String,String> map =new HashMap<String, String>();
//		
//		String id = request.getParameter("id");
//		List<Xxm2eJobCompleteDO> list =	xxm2eJobCompleteService.findListByExample(id);
//		
//		SearchConditions scs2 = new SearchConditions();
//		scs2.addCondition("code", list.get(0).getSubinventory());
//		List<BasicStorageinfoDO> basicStorageinfoDOs = basicwhService.findListByExample(scs2).getResults();
//		if(basicStorageinfoDOs.size() > 0){
//			map.put("whcode", basicStorageinfoDOs.get(0).getCode());
//			map.put("whname", basicStorageinfoDOs.get(0).getName());
//		}
//		map.put("transactionDate", DateUtil.dateToString(list.get(0).getTransactionDate(),"yyyy-MM-dd"));
//		AjaxUtil.printJSonArr(response, JSONObject.fromObject(map).toString());
//	}
//
//	
//	@RequestMapping(value = "/updateState")
//	public void updateState(HttpServletRequest request,HttpServletResponse response)throws Exception{
//		String id = request.getParameter("rows");
//		Map<String,String> map =new HashMap<String, String>();
//		try{
//			LogicMesWareDO logicMesWareDO = logicMesWareService.findListById(id);
//			logicMesWareDO.setBillstatus(Short.parseShort("1"));
//			logicMesWareService.update(logicMesWareDO,  SessionUtil.getUser(request));
//		map.put("msg", "SUCCESS");
//		}catch(Exception e){
//			e.printStackTrace();
//			map.put("msg", "ERROR");
//		}
//		AjaxUtil.printJSonArr(response, JSONObject.fromObject(map).toString());
//	}
//}
